<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('选择组织对象')" />
</head>
<body>
<form>
    <div style="padding: 0 10px;">
        <div class="north">
            <div class="layui-form-item">
                <div class="layui-inline" style="width:30%">
                    <label class="layui-form-label" style="padding: 9px 0;width:70px">机构编码</label>
                    <div class="layui-input-block" style="margin-left: 75px;">
                        <input id="orgid" type="text" name="orgid" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="width:30%">
                    <label class="layui-form-label" style="padding: 9px 0;width:70px">机构名称</label>
                    <div class="layui-input-block" style="margin-left: 75px;">
                        <input id="orgName" type="text" name="orgName" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="line-height: 34px;">
                    <a class="layui-btn layuiadmin-btn-order dhicon dh-search" id="btn-search"><span class="fa_span">查询</span></a>
                    <button type="reset" class="layui-btn layui-btn-primary dhicon dh-refresh reset" id="dh-resets"><span class="fa_span">重置</span></button>
                </div>
            </div>
        </div>
        <div class="south">
            <div class="left">
                <div th:style="${pagetype == 'checkbox'}?'float:left;':'float:left;width:100%'"><table class="layui-hide" id="dhtable" lay-filter="ftable"></table></div>
            </div>
        </div>
    </div>
</form>
<th:block th:include="include :: footer" />
<script>
    /*<![CDATA[*/
    var pagetype = "[[${pagetype}]]";
    var selectedObject = "[[${selectedObject}]]";
    /*]]>*/
    if(pagetype=="checkbox"){
        var typeobj = {type: 'checkbox'}
    }else{
        var typeobj = {type: 'radio'}
    }
    layui.use(['table','layer','jquery'], function () {
        var $ = layui.$,layer = layui.layer,table = layui.table,form = layui.form;
        $.tablelist.init({
            elem: '#dhtable'
            ,url: "/system/organization/orgObject"
            ,cols: [[
                {type:'numbers', fixed: 'left'}
                ,typeobj
                ,{field:'orgid', title: '机构编码',align: 'center',width: 80}
                ,{field:'orgKind', title: '机构类型',align: 'center',width: 100,hide:true}
                ,{field:'orgKindName', title: '机构类型名称',align: 'left',width: 280,hide:true}
                ,{field:'orgName', title: '机构名称',width: 260}
            ]
            ]
            ,height:300
        });

        if(pagetype=="checkbox"){
            //点击table行选中复选框
            $(document).on("click",".layui-table-body table.layui-table tbody tr",function(){
                var obj = event ? event.target : event.srcElement;
                var tag = obj.tagName;
                var checkbox = $(this).find("td div.laytable-cell-checkbox div.layui-form-checkbox I");
                if(checkbox.length!=0){
                    if(tag == 'DIV') {
                        checkbox.click();
                    }
                }
            });
            //点击复选框阻止冒泡
            $(document).on("click",".layui-form-checkbox",function(e){
                e.stopPropagation();
                var data = [], data2 = [];
                var checkStatus = table.checkStatus('dhtable');
                data = checkStatus.data;
                if(data.length > 0){$(".addbtn").removeClass("layui-btn-disabled");$(".addbtn").children().css('color','#fff');}else{$(".addbtn").addClass("layui-btn-disabled");$(".addbtn").children().css('color','#C9C9C9');}
            });
        }else{
            table.on('row(ftable)', function(obj){
//	             obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');//选中行样式
                obj.tr.find('input[lay-type="layTableRadio"]').prop("checked",true);

                var index = obj.tr.data('index')
                var thisData = table.cache.dhtable;	//dhtable 表名
                //重置数据单选属性
                layui.each(thisData, function(i, item){
                    if(index === i){
                        item.LAY_CHECKED = true;
                    } else {
                        delete item.LAY_CHECKED;
                    }
                });
                form.render('radio');
            });
        }
        $('#btn-search').on('click', function () {
            var orgid = $("#orgid").val();
            var orgName = $("#orgName").val();
            table.reload('dhtable', {url: "/system/organization/orgObject?orgName="+orgName+"&orgid="+orgid,page:{curr: 1}});
        });
    });
    var callbackdata = function () {
        var checkStatus = table.checkStatus('dhtable')
            ,data = checkStatus.data;//单选情况下只会返回一个
        return data;
    }
</script>
</body>
</html>